<template>
	<view>
		<view class="wrap">
			<view class="order-header">
				<view class="u-tabs-box">
					<u-tabs-swiper activeColor="#10beca" ref="tabs"
						:list="list" :current="current" @change="change" :is-scroll="false" swiperWidth="750">
					</u-tabs-swiper>
				</view>
				<view class="u-p-30 bg-white">
					<u-search v-model="key" :show-action="false" shape="square" clearabled @change="searchKeyword"></u-search>
				</view>
			</view>
			<swiper class="swiper-box" :current="swiperCurrent" @transition="transition"
				@animationfinish="animationfinish">
				<swiper-item class="swiper-item" v-for="(list,i) in orderList" :key="i">
					<scroll-view scroll-y style="height: 100%;width: 100%;" @scrolltolower="reachBottom">
						<!-- <u-cell-group class="u-m-b-20" v-if="orderList[i].length > 0">
							<u-cell-item :title="res.number" :title-style="{color: '#303133'}" v-for="(res, index) in orderList[i]" :key="res.id" :use-label-slot="true" @click="details(res)">
								<view slot="label">
									<view><text>出库站点：{{res.storenames.slice(1)}}</text></view>
									<view><text>接收打包站：{{res.packstationname}}</text></view>
									<view><text>出库数量：{{res.weight}}KG/{{res.quantity}}件</text></view>
								</view>
								<view slot="right-icon">
									<u-tag v-if="res.state == '已出库'" :text="res.state" mode="plain" size="mini" type="warning" />
									<u-tag v-if="res.state == '已完结'" :text="res.state" mode="plain" size="mini" type="success"/>
									<u-tag v-if="res.state == '已取消'" :text="res.state" mode="plain" size="mini" type="error"/>
								</view>
							</u-cell-item>
						</u-cell-group>
						<u-empty v-else text="您还没有相关的订单" mode="list"></u-empty> -->
						
						<view class="grid-box" v-for="(res, index) in orderList[i]" :key="res.id">
							<navigator class="order" @click="details(res)">
								<view class="top">
									<view class="left">
										<u-icon name="order" size="32" color="rgb(94,94,94)"></u-icon>
										<view class="store">{{res.number}}</view>
									</view>
									<view class="right">{{ res.state }}</view>
								</view>
								
								<view class="u-p-t-20">
									<view class="address">
										<!-- <u-icon name="map-fill" size="32"></u-icon> -->
										<text class="u-font-32">[出库站点]{{res.storenames}}</text>
									</view>
									<view class="address">
										<!-- <u-icon name="map-fill" size="32"></u-icon> -->
										<text class="u-font-32">[接收打包站]{{res.packstationname}}</text>
									</view>
									<view class="u-p-t-8">
										<view class="u-flex u-font-24">
											<text class="u-text-right">操作人：{{res.brothername}}</text>
										</view>
									</view>
								</view>
								
								<view class="middle" v-if="res.state == '已完结'">
									<view class="u-flex" style="justify-content: space-between;">
										<view class="">
											<text class="label u-tips-color">出库重量</text>
											<view class="u-m-t-8">
												<text class="u-flex-1 u-text-right u-font-36">{{res.state == '已完结'?`${res.weight}`:'--'}}</text>
												<text class="unit">公斤</text>
											</view>
										</view>
										<view class="">
											<text class="label u-tips-color">出库数量</text>
											<view class="u-m-t-8">
												<text class="u-flex-1 u-text-right u-font-36">{{res.state == '已完结'?`${res.quantity}`:'--'}}</text>
												<text class="unit">件</text>
											</view>
										</view>
										<view class="">
											<text class="label u-tips-color">出库价值</text>
											<view class="u-m-t-8">
												<text class="u-flex-1 u-text-right u-font-36">{{res.state == '已完结'?`${res.amount}`:'--'}}</text>
												<text class="unit">元</text>
											</view>
										</view>
									</view>
								</view>
								
								<view class="bottom" v-if="res.state == '已完结'">
									<view class="more">
										<view class="u-flex-1">
											<text class="u-font-24 u-tips-color">于{{res.endtime}}结单</text>
										</view>
										<!-- <text class="u-font-24 u-tips-color">{{$u.timeFrom(new Date(res.endtime), false)}}</text> -->
									</view>
								</view>
								
								<view class="bottom" v-if="res.state == '已出库'">
									<view class="more">
										<view class="u-flex-1">
											<text class="u-font-24 u-tips-color">于{{res.createddatetime}}建单</text>
										</view>
										<!-- <text class="u-font-24 u-tips-color">{{$u.timeFrom(new Date(res.endtime), false)}}</text> -->
									</view>
								</view>
							</navigator>
						</view>
					</scroll-view>
				</swiper-item>
			</swiper>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list: [
					{
						value: '',
						name: '全部'
					},
					{
						value: 1,
						name: '已出库'
					},
					{
						value: 2,
						name: '已完结'
					},
					{
						value: 3,
						name: '已取消'
					}
				],
				current: 0,
				swiperCurrent: 0,
				tabsHeight: 0,
				dx: 0,
				loadStatus: ['loadmore', 'loadmore'],
				PageIndex: 1,
				PageSize: 20,
				noMore: false,
				key: '',
				orderList: [[],[],[],[]]
			}
		},
		onShow() {
			this.orderList[this.swiperCurrent] = []
			this.PageIndex = 1
			this.getOrderList(this.swiperCurrent);
		},
		onPullDownRefresh() {
			this.orderList[this.swiperCurrent] = []
			this.PageIndex = 1
			this.getOrderList(this.swiperCurrent).then(() => {
				uni.stopPullDownRefresh(); //停止当前页面下拉刷新
			})
		},
		methods: {
			// 查看详情
			details(item){
				uni.navigateTo({
					url: '/pages/brother/outOrder/details/details?id='+item.id
				})
			},
			// 新建入库单
			// create(){
			// 	uni.navigateTo({
			// 		url: '/pages/brother/incomOrder/create/create'
			// 	})
			// },
			reachBottom() {
				// 此tab为空数据
				this.PageIndex += 1
				if (!this.noMore) {
					this.getOrderList(this.swiperCurrent).then((row) => {
						if (row.length == 0) {
							this.noMore = true
						}
					})
				}
			},
			// 页面数据
			getOrderList(idx) {
				this.loadStatus.splice(this.swiperCurrent, 1, "loading")
			
				return this.$u.post('/Store/OutOrder/List', {
					"PageIndex": this.PageIndex,
					"PageSize": this.PageSize,
					"key": this.key,
					"state": this.list[this.swiperCurrent].value
					// "Order": [{column:'Sort', isdesc: true}, {column:'Id', isdesc: true}],
					// "assignmentState": 0,
					// "state": 0,
					// "manageState": 0
				}).then((res) => {
					if (res.rows.length > 0) {
						res.rows.forEach((item) => {
							this.orderList[idx].push(item)
						})
						if (res.rows.length < this.PageSize) {
							this.loadStatus.splice(this.swiperCurrent, 1, "nomore")
						} else {
							this.loadStatus.splice(this.swiperCurrent, 1, "loadmore")
						}
					} else {
						this.loadStatus.splice(this.swiperCurrent, 1, "nomore")
					}
					this.$forceUpdate()
					return res.rows
				})
			},
			// tab栏切换
			change(index) {
				this.PageIndex = 1;
				this.swiperCurrent = index;
				this.orderList[index] = [];
				this.noMore = false;
				this.getOrderList(index);
			},
			transition({
				detail: {
					dx
				}
			}) {
				this.$refs.tabs.setDx(dx);
			},
			animationfinish({
				detail: {
					current
				}
			}) {
				this.$refs.tabs.setFinishCurrent(current);
				this.swiperCurrent = current;
			
				if (current != this.current) { //滑动切换到其他分类时
					this.current = current;
					this.orderList[this.current] = []
					this.loadStatus.splice(this.current, 1, "loadmore")
					this.getOrderList(this.current)
				} else {
					this.current = current;
				}
			},
			searchKeyword(val){
				this.key = val
				this.PageIndex = 1;
				this.orderList[this.swiperCurrent] = [];
				this.getOrderList(this.swiperCurrent);
			}
		}
	}
</script>

<style lang="scss" scoped>
	
	.order-header {
		box-sizing: content-box;
		padding-top: 1px;
	
		.header {
			height: 44px;
			padding: 0 20rpx;
			display: flex;
			align-items: center;
		}
	}
	
	.wrap {
		display: flex;
		flex-direction: column;
		height: calc(100vh - var(--window-top));
		width: 100%;
	}
	
	.swiper-box {
		flex: 1;
	}
	
	.swiper-item {
		height: 100%;
		.pack{
			display: flex;
			align-items: center;
			width: 640rpx;
			margin: 20rpx 0;
			.item{
				width: 200rpx;
				flex: 1;
				
				.name{
					color: $u-color-dark;
				}
				.text{
				}
			}
			// .icon{
			// 	font-size: 60rpx;
			// 	padding: 0 80rpx;
			// 	transform: rotate(90deg);
			// 	color: var(--gray);
			// }
		}
		.time{
			color: $u-color-dark;
		}
	}
	.order {
		// width: 710rpx;
		// background-color: #ffffff;
		// margin: 20rpx auto;
		// border-radius: 20rpx;
		// box-sizing: border-box;
		// padding: 20rpx;
		// font-size: 28rpx;
	
		.top {
			display: flex;
			justify-content: space-between;
			align-items: center;
	
			.left {
				display: flex;
				align-items: center;
	
				.store {
					margin: 0 10rpx;
					font-size: 32rpx;
					display: flex;
					align-items: center;
				}
			}
	
			.right {
				color: $u-type-warning-dark;
			}
		}
	
		.item {
			display: flex;
			margin: 20rpx 0 0;
			justify-content: space-between;
	
			.left {
				margin-right: 20rpx;
	
				image {
					width: 160rpx;
					height: 160rpx;
					border-radius: 10rpx;
				}
			}
	
			.content {
				.title {
					font-size: 28rpx;
					line-height: 50rpx;
					font-weight: bold;
				}
	
				.type {
					margin: 10rpx 0;
					font-size: 24rpx;
					color: $u-tips-color;
				}
			}
	
			.right {
				margin-left: 10rpx;
				text-align: right;
	
				.decimal {
					font-size: 24rpx;
					margin-top: 4rpx;
				}
	
				.number {
					color: $u-tips-color;
					font-size: 24rpx;
				}
			}
		}
	
		.total {
			text-align: right;
			font-size: 24rpx;
	
			.total-price {
				font-size: 32rpx;
				color: $u-color-orange;
			}
		}
	
		.middle {
			font-size: 24rpx;
			margin: 20rpx 0;
			line-height: 40rpx;
			.label{
				
			}
			.unit{
				font-size: 24rpx;
				// color: $u-tips-color;
			}
		}
	
		.bottom {
			// display: flex;
			margin-top: 20rpx;
			// justify-content: space-between;
			// align-items: center;
			.more{
				display: flex;
				justify-content: center;
				align-items: center;
			}
			.btn {
				line-height: 52rpx;
				width: 160rpx;
				border-radius: 26rpx;
				border: 2rpx solid $u-border-color;
				font-size: 26rpx;
				text-align: center;
				color: $u-type-info-dark;
			}
			.evaluate {
				color: $u-type-warning-dark;
				border-color: $u-type-warning-dark;
			}
		}
	}
</style>
